#!/bin/bash

# 获取脚本所在目录
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# 获取 EFS ID
EFS_ID=$(aws efs describe-file-systems --region ap-northeast-1 --query 'FileSystems[0].FileSystemId' --output text)

# 更新 storage class 文件
if [[ "$OSTYPE" == "darwin"* ]]; then
    # macOS
    sed -i '' "s/fileSystemId: .*/fileSystemId: $EFS_ID/" "$SCRIPT_DIR/efs-storage-class.yml"
else
    # Linux
    sed -i "s/fileSystemId: .*/fileSystemId: $EFS_ID/" "$SCRIPT_DIR/efs-storage-class.yml"
fi

# 应用配置
kubectl apply -f "$SCRIPT_DIR/efs-storage-class.yml"

# 验证
kubectl get sc efs-storage-class
